#ifndef __LOAD_OBJ__
#define __LOAD_OBJ__
#include <fstream>
#include <vector>
#include <string>
#include <sys/stat.h>
#include "utils.h"
#include "mesh.h"

#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>

using namespace std;

bool fileExists(char const *path);

bool isdir(char const *path);

bool isfile(char const *path);

string dir_(char const *path);

vector<string> loadContent(char const *path);

vector<vector<string>> processContents(vector<string> contents, string flag);

vector<vector<string>> loadMeshContents(char const *path);

vector<vector<string>> loadMtlContents(char const *path);

vector<Mesh> processModel(char const *path);

class LoadModel {
    public:
        vector<Mesh> meshes;
        vector<Texture> textureLoaded;
        string dirctory;
        LoadModel(string path) {
            Assimp::Importer import;
            const aiScene *scene = import.ReadFile(string(path), aiProcess_Triangulate | aiProcess_FlipUVs);    

            if(!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) 
            {
                printf("ERROR::ASSIMP::%s\n", import.GetErrorString());
            } else {
                dirctory = path.substr(0, path.rfind("/"));
                processNode(scene->mRootNode, scene);
            }
        }
        void processNode(aiNode *node, const aiScene *scene);
        vector<Texture> processTextures(aiMaterial* mat, aiTextureType type, string typeName);

};

#endif